<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */
/**
 * 
 * @param string $db Common database connection string parameter
 * @return string $CI Returning the warehousename from warehouses table and shows in drop down menu
 */
function getWarehouses($db) {
    $query = "SELECT warehouse_id, warehousename FROM warehouses";
        try {
            $stmt = $db->prepare($query);
            $stmt->execute();
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        $rows = $stmt->fetchAll();

        foreach($rows as $row1) {
            $CI.="<option value='{$row1["warehouse_id"]}'>";
                $CI.=$row1['warehousename'];
            $CI.="</option>";
            $CI++;
        }
        return $CI;
}
/**
 * 
 * @param string $db Common database connection string parameter
 * @return string $CI Returning the warehousename and customerdefinedname from warehouses table and shows in drop down menu
 */
function getWarehousesCode($db) {
    $query = "SELECT warehouse_id, warehousename, customerdefinedname FROM warehouses";
        try {
            $stmt = $db->prepare($query);
            $stmt->execute();
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
        }
        $rows = $stmt->fetchAll();

        foreach($rows as $row1) {
            $CI.="<option value='{$row1["warehouse_id"]}'>";
                $CI.=$row1['warehousename'] . " (" . $row1['customerdefinedname'] . ")" ;
            $CI.="</option>";
            $CI++;
        }
        return $CI;
}
/**
 * 
 * @param numeric $id gets the warehouse id from warehouse table
 * @param string $db Common database connection string parameter
 * @return string $row1 returning warehousename from the warehouse table
 */
function getWarehouse($id, $db){
	$query = "SELECT warehouse_id, warehousename FROM warehouses WHERE warehouse_id={$id} LIMIT 1";
    try {
        $stmt = $db->prepare($query);
        $stmt->execute();
    } catch (PDOException $ex) {
        die("Failed to run query: " . $ex->getMessage());
    }
    $row1 = $stmt->fetch();
    return $row1['warehousename'];
}
?>
